package com.democxy.modules.cms.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

import com.democxy.common.baseData.ResponeData;
import com.democxy.common.utils.StringUtils;
import com.democxy.modules.cms.entity.AdHref;
import com.democxy.modules.cms.service.AdHrefService;


/**
 * 广告管理Controller
 * @author democxy
 * @version v1.0
 */
@RestController
@RequestMapping(value = "/admin/cms/adHref")
public class AdHrefController{

	@Autowired
	private AdHrefService adHrefService;
	
	@RequestMapping(value = "list")
	public ResponeData<PageInfo<AdHref>> list(@RequestBody AdHref adHref) {
		PageHelper.startPage(adHref.getPageNo(),10);
		List<AdHref> list = adHrefService.findList(adHref);
		PageInfo<AdHref> pageInfo = new PageInfo<AdHref>(list, 10);
		return new ResponeData<PageInfo<AdHref>>(pageInfo);
	}

	@RequestMapping(value = "save")
	public ResponeData<String> save(@RequestBody AdHref adHref) {
		adHrefService.save(adHref);
		return new ResponeData<>("添加成功");
	}
	
	@RequestMapping(value = "delete")
	public  ResponeData<String> delete(@RequestBody AdHref adHref) {
		adHrefService.delete(adHref.getId());
		return new ResponeData<>("删除成功");
	}
	
	@RequestMapping(value = "get/{id}")
	public  ResponeData<AdHref> get(@PathVariable("id") String id) {
		AdHref byId = adHrefService.getById(id);
		return new ResponeData<>(byId);
	}

}